import defaultSettings from '@/settings'

const { showSettings, fixedHeader, sidebarLogo, lang } = defaultSettings

// const getPageSettings = () => {
//   const settings = localStorage.getItem('pageSettings')
//   if (settings === 'undefineed')
// }

const state = {
  showSettings: showSettings,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo,
  lang: lang,
  pageSettings: JSON.parse(localStorage.getItem('pageSettings')) || {}
}

console.log(state.pageSettings)

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  },
  SET_PAGE_SETTINGS: (state, settings) => {
    state.pageSettings = Object.assign(state.pageSettings, settings)
    localStorage.setItem('pageSettings', JSON.stringify(state.pageSettings))
  },
  GET_PAGE_SETTINGS: (state, key) => {
    return state.pageSettings[key];
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  },
  setPageSettings({ commit }, data) {
    commit('SET_PAGE_SETTINGS', data)
  },
  getPageSettings({ commit }, k) {
    commit('GET_PAGE_SETTINGS', k)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
